package com.langll.ai.minio.controller;

import com.langll.ai.minio.model.UploadFileVo;
import com.langll.ai.minio.service.IAiDocumentFileService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author langll2
 * @since 2025-04-11
 */
@RestController
@RequestMapping("/minio")
@Tag(name = "minio 对象数据库实践", description = "对象数据库管理")
@RequiredArgsConstructor
public class AiDocumentFileController {

    private final IAiDocumentFileService iAiDocumentFileService;

    @Operation(summary = "上传文件并保存")
    @PostMapping("/uploadFile")
    public ResponseEntity<UploadFileVo> uploadFile(MultipartFile file) {
        return ResponseEntity.ok(iAiDocumentFileService.saveFile(file));
    }

    @Operation(summary = "获取文件列表")
    @GetMapping("/listFile")
    public ResponseEntity<List<UploadFileVo>> listFile() {
        return ResponseEntity.ok(iAiDocumentFileService.listFile());
    }

    @Operation(summary = "删除文件")
    @PostMapping("/deleteFileByFileObjectName")
    public ResponseEntity<Boolean> deleteFile(@RequestBody UploadFileVo fileObject) {
        return ResponseEntity.ok(iAiDocumentFileService.deleteFile(fileObject.getFileObjectName()));
    }

    @Operation(summary = "删除文件")
    @PostMapping("/deleteFileById")
    public ResponseEntity<Boolean> deleteFile(@RequestBody Serializable id) {
        return ResponseEntity.ok(iAiDocumentFileService.deleteFile(id));
    }

    @Operation(summary = "更新文件并保存")
    @PostMapping("/updateFile")
    public ResponseEntity<UploadFileVo> updateFile(@RequestBody UploadFileVo oldFileObject, MultipartFile file) {
        return ResponseEntity.ok(iAiDocumentFileService.updateFile(oldFileObject.getFileObjectName(), file));
    }

    @Operation(summary = "向量化文档")
    @PostMapping("/vectorFile")
    public ResponseEntity<UploadFileVo> vectorFile(@RequestBody Serializable id) {
        return ResponseEntity.ok(iAiDocumentFileService.vectorFile(id));
    }

    @Operation(summary = "下载文档")
    @PostMapping("/downloadFile")
    public ResponseEntity<UploadFileVo> downloadFile(@RequestBody Serializable id) {
        return ResponseEntity.ok(iAiDocumentFileService.downloadFile(id));
    }
}
